package com.algorithm.learning.binarysearch;

/**
 * @program: algorithm-learning
 * @description:
 * @author: YuKai Fan
 * @create: 2024/8/16 23:02
 **/
public class 第一个错误的版本 {

    public static void main(String[] args) {
        System.out.println(firstBadVersion(1, 1));
    }

    public static int firstBadVersion(int n, int bad) {
        int left = 1;
        int right = n;
        while (left < right) {
            int mid = left + (right - left) / 2;
            if (isBadVersion(mid, bad)) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        return left;
    }

    public static boolean isBadVersion(int v, int b) {
        return v == b;
    }
}
